<template>
    <div>
        <table class="table">
            <tbody class="table">
                <tr>
                    <td><span style="color: red;">*</span>门店名称</td>
                    <td>
                        <input type="text" v-model="data.shopName">
                    </td>
                </tr>
                <tr>
                    <td><span style="color: red;">*</span>营业开始时间</td>
                    <td>
                        <input type="date" v-model="data.strTime">
                    </td>
                </tr>
                <tr>
                    <td><span style="color: red;">*</span>营业结束时间</td>
                    <td>
                        <input type="date" v-model="data.endTime">
                    </td>
                </tr>
                <tr>
                    <td><span style="color: red;">*</span>服务范围</td>
                    <td>
                        <select v-model="data.seid">
                            <option :value="0">=请选择=</option>
                            <option v-for="e in showdata" :value="e.seid">{{e.sname}}</option>
                        </select>
                    </td>
                </tr>
                    <tr>
                    <td><span style="color: red;">*</span>门店logo</td>
                    <td>
                        <input type="file" @change="up1">
                        <img :src="'https://localhost:7194'+data.logo" style="width: 60px;height: 60px;">
                    </td>
                </tr>
                    <tr>
                    <td><span style="color: red;">*</span>门店照片</td>
                    <td>
                        <input type="file" @change="up2">
                        <img :src="'https://localhost:7194'+data.shopLog" style="width: 60px;height: 60px;">
                    </td>
                </tr>
                <tr>
                    <td><span style="color: red;">*</span>门店电话</td>
                    <td>
                        <input type="text" v-model="data.phone">
                    </td>
                </tr>
                <tr>
                    <td><span style="color: red;">*</span>门店地址</td>
                    <td>
                        <input type="text" v-model="data.address">
                    </td>
                </tr>
                <tr>
                    <td><span style="color: red;">*</span>门店状态</td>
                    <td>
                        <input type="radio" name="s1" :value="true" v-model="data.isStatus">启用
                        <input type="radio" name="s1" :value="false" v-model="data.isStatus">禁用
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td colspan="2">
                        <input type="button" value="修改" @click="upd">
                        <input type="button" value="返回" @click="sh">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref,onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router';

onMounted(()=>{
showss();
back();
})
const showdata=ref([{
"seid": 1,
    "sname": ""
}])
const showss=()=>{
    axios.get("https://localhost:7194/api/Shop/GetServices").then(res=>{
        showdata.value=res.data;
    })
}
//logo
const up1=(a:any)=>{
    var f=a.target.files[0];
    var fd=new FormData();
    fd.append("files",f)
    axios.post("https://localhost:7194/api/Shop/Up",fd).then(res=>{
        data.value.logo=res.data;
    })
}
//门店照片
const up2=(a:any)=>{
    var f=a.target.files[0];
    var fd=new FormData();
    fd.append("files",f)
    axios.post("https://localhost:7194/api/Shop/Up",fd).then(res=>{
        data.value.shopLog=res.data;
    })
}
const router=useRouter();
const route=useRoute();
//数据回显
const back=()=>{
    var d=route.query.id;
    axios.get("https://localhost:7194/api/Shop/GetShopByid",{params:{id:d}}).then(res=>{
        data.value=res.data;
        data.value.strTime=data.value.strTime.substring(0,10)
        data.value.endTime=data.value.endTime.substring(0,10)
    })
}
const data=ref({
    "sid": 0,
  "shopName": "",
  "strTime": "",
  "endTime": "",
  "seid": 0,
  "logo": "",
  "shopLog": "",
  "phone": "",
  "address": "",
  "isStatus": true,
  "isDelete": false
})

const upd=()=>{
    axios.put("https://localhost:7194/api/Shop/UpdateShop",data.value).then(res=>{
        if(res.data>0){
            alert("修改成功");
            router.push({
                path:'/'
            })
        }else{
            alert("修改失败");
        }
    })
}
const sh=()=>{
    router.push({
        path:'/'
    })
}
</script>

<style scoped>

</style>